package com.tsky.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Map;

public class DataSource {

	private Connection conn = null;
	private Statement stmt = null;
	private ResultSet rs = null;

	public  Connection InitConn() throws Exception
	{
//		   String XmlPatch =IpccInsert.class.getClassLoader().getResource("DataBaseConfig.xml").getPath();
//		   SAXBuilder sb=new SAXBuilder(); 
//		   Document doc=sb.build(XmlPatch); //构造文档对象
//		   Element root=doc.getRootElement(); //获取根元素 
		// /oracle/app/oracle/product/11.2.0/client_1/network/admin bh01-scan.gdsai.com
//		   String sid = "(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = bh01-scan.gdsai.com)(PORT = 1521))(CONNECT_DATA =  (SERVER = DEDICATED)  (SERVICE_NAME = etl_high))  )";
//			String url = "jdbc:oracle:thin:@192.168.35.1:1521:bighead";
//			String url = "jdbc:mysql://localhost:3306/test";
		   
		  // String url  =  root.getChildText("Url");
//		    String username ="root"; 
		   //System.out.println("url:::::::::::::::"+url);
		   //String username  = root.getChildText("User");
			String sid = "(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))(CONNECT_DATA =  (SERVER = DEDICATED)  (SERVICE_NAME = bone))  )";
			String url = "jdbc:oracle:thin:@"+sid;
			String username ="sigal"; 
		    String password ="sigal"; 
		    
		    try {
		    	conn =DriverManager.getConnection(url, username, password);
			} catch (Exception e) {
				System.out.println("client disconnectioned ");
				e.printStackTrace();
			}
		   
		    return conn; 
	}

	
	public  Statement InitStatement() throws Exception
	{
		if(conn==null || conn.isClosed())
		{
		   conn =InitConn();
		}
		
	   //conn.setAutoCommit(true);
	   stmt = conn.createStatement(); 		   
	   return stmt;		
	}
}

